package math.vectorSpace.R3.object;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;

import math.vectorSpace.R2.Point2D;
import math.vectorSpace.R3.Point3D;
import math.vectorSpace.R3.visualization.Render3D;
import math.vectorSpace.R3.Vector3D;
import math.vectorSpace.R3.visualization.RenderOrthographic;
import math.vectorSpace.R3.visualization.VisualizationProperties;

public class Cylinder extends Object3D {

    public Cylinder(Point3D center, double radius1, double radius2,
            double height) {
        this.center = center;
        totalPts = 20;
        v = new Vector3D[totalPts];

        // Bottom circle centre
        v[0] = new Vector3D(0, 0, -height / 2.0);

        // Top circle centre
        v[1] = new Vector3D(0, 0, height / 2.0);

        // Cross section vectors
        v[2] = new Vector3D(0, radius1, 0);
        v[3] = new Vector3D(radius2, 0, 0);

    }

    @Override
    public void draw(Render3D display, Graphics2D g,
            VisualizationProperties properties) {
        /*
        double bottom, top, radius1, radius2;
        bottom = display.distance(center.add(v[0]));
        top = display.distance(center.add(v[1]));
        radius1 = v[2].length();
        radius2 = v[3].length();

        Point3D c;
        Point2D temp;
        double deltaX, deltaY;

        if (bottom < top) {
            c = center.add(v[0]);
            temp = display.project(center.add(v[1])).subtract(display.project(c));
        } else {
            c = center.add(v[1]);
            temp = display.project(center.add(v[0])).subtract(display.project(c));
        }
        deltaX = temp.getX();
        deltaY = temp.getY();

        Point2D[] rendered = new Point2D[12];

        // Starting at the top, going clockwise around the circle
        Point3D pt1, pt2, pt3, pt4;
        pt1 = c.add(v[2]);
        pt2 = c.add(v[3]);
        pt3 = c.add(v[2].invert());
        pt4 = c.add(v[3].invert());

        // Point 1, 
        rendered[0] = display.project(pt1);
        rendered[1] = display.project(pt1.add(new Vector3D(radius1 * 0.552267,
                v[3])));
        rendered[2] = display.project(pt2.add(new Vector3D(radius2 * 0.552267,
                v[2])));

        // Point 2
        rendered[3] = display.project(pt2);
        rendered[4] = display.project(pt2.add(new Vector3D(radius2 * 0.552267,
                v[2].invert())));
        rendered[5] = display.project(pt3.add(new Vector3D(radius1 * 0.552267,
                v[3])));

        // Point 3
        rendered[6] = display.project(pt3);
        rendered[7] = display.project(pt3.add(new Vector3D(radius1 * 0.552267,
                v[3].invert())));
        rendered[8] = display.project(pt4.add(new Vector3D(radius2 * 0.552267,
                v[2].invert())));

        // Point 4
        rendered[9] = display.project(pt4);
        rendered[10] = display.project(pt4.add(new Vector3D(radius2 * 0.552267,
                v[2])));
        rendered[11] = display.project(pt1.add(new Vector3D(radius1 * 0.552267,
                v[3].invert())));

        GeneralPath circle = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);

        circle.moveTo(rendered[0].getX(), rendered[0].getY());

        for (int i = 1; i < 9; i += 3) {
            circle.curveTo(rendered[i].getX(), rendered[i].getY(),
                    rendered[i + 1].getX(), rendered[i + 1].getY(),
                    rendered[i + 2].getX(), rendered[i + 2].getY());
        }

        circle.curveTo(rendered[10].getX(), rendered[10].getY(),
                rendered[11].getX(), rendered[11].getY(), rendered[0].getX(),
                rendered[0].getY());

        for (int i = 0; i < 12; i++) {
            rendered[i].setPoint(rendered[i].getX() + deltaX,
                    rendered[i].getY() + deltaY);
        }

        GeneralPath surface = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 4);

        g.setColor(new Color(0.0f, 0.0f, 0.0f));

        surface.moveTo(rendered[0].getX(), rendered[0].getY());

        for (int i = 1; i < 3; i += 3) {
            surface.curveTo(rendered[i].getX(), rendered[i].getY(),
                    rendered[i + 1].getX(), rendered[i + 1].getY(),
                    rendered[i + 2].getX(), rendered[i + 2].getY());
        }

        surface.lineTo(rendered[3].getX() - deltaX, rendered[3].getY() - deltaY);

        for (int i = 3; i > 1; i -= 3) {
            surface.curveTo(rendered[i].getX() - deltaX, rendered[i].getY() - deltaY,
                    rendered[i - 1].getX() - deltaX, rendered[i - 1].getY() - deltaY,
                    rendered[i - 2].getX() - deltaX, rendered[i - 2].getY() - deltaY);
        }

        surface.lineTo(rendered[0].getX() - deltaX, rendered[0].getY() - deltaY);

        g.fill(surface);

        g.setColor(new Color(0.0f, 0.0f, 0.0f));
        g.fill(circle); */
    }
}
